<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

<html>
	<head>
		<title>权限系统注册管理</title>
		<%@ include file="/common/meta.jsp"%>
		<%@ include file="/common/jquery-ui-inc.jsp"%>
		<script type="text/javascript" src="${ctx}/js/date.js"></script>

		<script>
//$.messager.defaults={ok:"确定",cancel:"取消"};   

$(function() {
	$('#sysList').datagrid( {
		title : '工作流系统注册列表',
		url : '${ctx}/flow/system/flow-sys!data.action',
		loadMsg : '数据载入中，请稍后……',
		nowrap : false,
		//striped: true,
		collapsible : false,
		fitColumns : true,
		pagination : true,
		singleSelect : true,
		rownumbers : true,
		remoteSort : false,
		pageList : [ 15, 30, 50 ],
		idField : 'sysId',
		frozenColumns : [ [ {
			title : '中文名称',
			field : 'sysCname',
			width : 200,
			formatter : function(value) {
				return '<span style="color:blue">' + value + '</span>';
			}
		} ] ],
		columns : [ [ {
			field : 'sysEname',
			title : '英文标识',
			width : 100,
			sorter : function(a, b) {
				return (a > b ? 1 : -1);
			}
		}, {
			field : 'sysUrl',
			title : '系统URL',
			width : 100,
			sorter : function(a, b) {
				return (a > b ? 1 : -1);
			}
		}, {
			field : 'createTime',
			title : '创建时间',
			width : 100,
			sorter : function(a, b) {
				return (a > b ? 1 : -1);
			}
		}, {
			field : 'createUser',
			title : '创建人',
			width : 100
		}] ],

		toolbar : [ {
			text : '增加',
			iconCls : 'icon-add',
			handler : function() {
				addSys();
			}

		}, '-', {
			text : '修改',
			iconCls : 'icon-edit',
			handler : function() {
				editSys();
			}
		}, '-', {
			text : '删除',
			iconCls : 'icon-cut',
			handler : function() {
				delSys();
			}
		} ],
		onDblClickRow:function(row){
					editSys();
		}
	});
});

function delSys() {
	var node = getSelected();
	if (node) {
		$.messager.confirm('确认', '您确定要删除:<font color="red">' + node.sysCname + '</font> ？',
				function(r) {
					if (r) {
						$.ajax( {
							type : "post",
							url : "${ctx}/flow/system/flow-sys!delete.action?sysId="
									+ node.sysId,
							beforeSend : function(XMLHttpRequest) {
								//ShowLoading();
							},
							success : function(data, textStatus) {
								var result = jQuery.parseJSON(data);
								if(result.flag=="T"){
									$.messager.alert('结果', '操作成功', 'info');
									var rowIndex = $('#sysList').datagrid(
											'getRowIndex', node);
									$('#sysList').datagrid('deleteRow', rowIndex);
								}else{
									$.messager.alert('结果',result.msg,'warning');
								}
							
								
							},
							complete : function(XMLHttpRequest, textStatus) {
								//HideLoading();
						},
						error : function() {
							//请求出错处理
						}
						});
					}
				});
	}

}

function editSys() {
	var node = getSelected();
	if (node) {
		$('#sysAddFrame').html('');
		var url = '${ctx}/flow/system/flow-sys!toSave.action?sysId=' + node.sysId;
		$('#sysAddFrame').attr("src", url);
		$('#sysAddWin').window('open');
	}
}



function closeAddWin(){
	$('#sysAddWin').window('close');
}

function addSys() {
	$('#sysAddFrame').html('');
	var url = '${ctx}/flow/system/flow-sys!toSave.action';
	$('#sysAddFrame').attr("src", url);
	$('#sysAddWin').window('open');

}

function getSelected() {
	var selected = $('#sysList').datagrid('getSelected');
	if (selected) {
		return selected;
	} else {
		$.messager.alert('提示', '请选择要操作的数据', 'info');
	}
}

function reload(){
	$('#sysList').datagrid('reload');
}
		
	function lockQuery(){					
	    var queryParams = $('#sysList').datagrid('options').queryParams;
	     	var opt = $('#sysList').datagrid('options'); 
	       	 $('#sysList').datagrid('options').pageNumber=1;
	     	 queryParams.sysCname = $('#sysCname').val();
	     	 queryParams.sysEname = $('#sysEname').val();
	          reload(); 
	         var page = $('#sysList').datagrid('getPager');
			 page.pagination({pageNumber:1,pageSize:opt.pageSize});
	  }
	function clearQuery(){					
	    $('#sysCname').val('');
	    $('#sysEname').val('');
	    lockQuery(); 
	 }
	  
			
	</script>
	</head>

	<body>
		<table class="datagrid-body">
			<tr>
				<td class="datagrid-header">
					中文名称
				</td>
				<td>
					<input name="sysCname" id="sysCname" value=""/>
				</td>
				<td class="datagrid-header">
					英文标识
				</td>
				<td>
					<input name="sysEname" id="sysEname" value=""/>
				</td>
				<td>
					<a class="easyui-linkbutton" iconCls="icon-search"
						onclick="lockQuery();">查询</a>
					<a class="easyui-linkbutton" iconCls="" onclick="clearQuery();">清空</a>
				</td>
			</tr>
		</table>


		<table id="sysList"></table>

		<div id="sysAddWin" class="easyui-window" title="工作流系统注册信息"
			style="padding: 5px; width: 600px; height: 300;"
			iconCls="icon-search" closed="true" maximizable="false"
			minimizable="false" collapsible="false">
			<iframe frameborder="0" id="sysAddFrame" height="100%" width="100%"
				scrolling="yes" frameborder="0"></iframe>
		</div>

	</body>
</html>